package com.example.jiaopin.Controller;
import com.example.jiaopin.Service.UserService;
import com.example.jiaopin.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{userID}")
    public User getUserById(@PathVariable Integer userID) {
        return userService.getUserById(userID);
    }

    @PostMapping("/")
    public void insertUser(@RequestBody User user) {
        userService.insertUser(user);
    }

    @PutMapping("/{userID}")
    public void updateUser(@PathVariable Integer userID, @RequestBody User user) {
        user.setUserID(userID);
        userService.updateUser(user);
    }

    @DeleteMapping("/{userID}")
    public void deleteUser(@PathVariable Integer userID) {
        userService.deleteUser(userID);
    }
}
